{% extends "base.html" %}

{% block title %}超市列表 - 妙趣拾光锦盒管理系统{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12 d-flex justify-content-between align-items-center">
        <h2 class="mb-0"><i class="fas fa-store me-2"></i>超市列表</h2>
        <div>
            <a href="{{ url_for('supermarket.applications') }}" class="btn btn-info me-2">
                <i class="fas fa-clipboard-list me-1"></i>
                超市申请管理
                {% set pending_count = pending_application_count|default(0) %}
                {% if pending_count > 0 %}
                <span class="badge bg-danger ms-1">{{ pending_count }}</span>
                {% endif %}
            </a>
            <a href="{{ url_for('supermarket.add') }}" class="btn btn-primary">
                <i class="fas fa-plus-circle me-1"></i>添加超市
            </a>
        </div>
    </div>
</div>

<!-- 筛选器 -->
<div class="card mb-4 shadow-sm">
    <div class="card-header bg-light">
        <h5 class="mb-0"><i class="fas fa-filter me-2"></i>筛选条件</h5>
    </div>
    <div class="card-body">
        <form method="GET" action="{{ url_for('supermarket.list') }}">
            <div class="row">
                <div class="col-md-4 mb-2">
                    <label for="name" class="form-label">超市名称</label>
                    <input type="text" class="form-control" id="name" name="name" value="{{ request.args.get('name', '') }}">
                </div>
                <div class="col-md-4 mb-2">
                    <label for="status" class="form-label">营业状态</label>
                    <select class="form-select" id="status" name="status">
                        <option value="">全部</option>
                        <option value="1" {% if request.args.get('status') == '1' %}selected{% endif %}>营业中</option>
                        <option value="2" {% if request.args.get('status') == '2' %}selected{% endif %}>暂停营业</option>
                    </select>
                </div>
                <div class="col-md-4 mb-2">
                    <label for="address" class="form-label">地址关键词</label>
                    <input type="text" class="form-control" id="address" name="address" value="{{ request.args.get('address', '') }}">
                </div>
            </div>
            <div class="d-flex justify-content-end mt-3">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-search me-1"></i>查询
                </button>
                <a href="{{ url_for('supermarket.list') }}" class="btn btn-secondary ms-2">
                    <i class="fas fa-redo me-1"></i>重置
                </a>
            </div>
        </form>
    </div>
</div>

<!-- 超市列表 -->
<div class="card shadow-sm">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover table-sortable">
                <thead>
                    <tr>
                        <th data-sort="id" scope="col">#</th>
                        <th data-sort="name" scope="col">超市名称</th>
                        <th data-sort="address" scope="col">地址</th>
                        <th data-sort="phone" scope="col">联系电话</th>
                        <th data-sort="hours" scope="col">营业时间</th>
                        <th data-sort="status" scope="col">状态</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for market in supermarkets %}
                    <tr>
                        <td data-id="{{ market.market_id }}">{{ market.market_id }}</td>
                        <td>
                            {% if market.logo_url %}
                            <img src="{{ market.logo_url }}" alt="{{ market.name }}" class="me-2" style="width: 30px; height: 30px; object-fit: cover;">
                            {% endif %}
                            {{ market.name }}
                        </td>
                        <td>{{ market.address }}</td>
                        <td>{{ market.phone }}</td>
                        <td>{{ market.business_hours }}</td>
                        <td data-status="{{ market.status }}">
                            {% if market.status == 1 %}
                            <span class="badge bg-success">营业中</span>
                            {% else %}
                            <span class="badge bg-secondary">暂停营业</span>
                            {% endif %}
                        </td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('supermarket.detail', market_id=market.market_id) }}" class="btn btn-sm btn-info">
                                    <i class="fas fa-info-circle"></i>
                                </a>
                                <a href="{{ url_for('supermarket.edit', market_id=market.market_id) }}" class="btn btn-sm btn-primary">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <a href="{{ url_for('supermarket.toggle_status', market_id=market.market_id) }}" class="btn btn-sm {% if market.status == 1 %}btn-warning{% else %}btn-success{% endif %}">
                                    <i class="fas {% if market.status == 1 %}fa-eye-slash{% else %}fa-eye{% endif %}"></i>
                                </a>
                                <a href="{{ url_for('supermarket.delete', market_id=market.market_id) }}" class="btn btn-sm btn-danger btn-delete">
                                    <i class="fas fa-trash"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="7" class="text-center py-4">
                            <div class="text-muted">
                                <i class="fas fa-store fa-3x mb-3"></i>
                                <p>暂无超市数据</p>
                                <a href="{{ url_for('supermarket.add') }}" class="btn btn-primary btn-sm">
                                    <i class="fas fa-plus-circle me-1"></i>添加超市
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
